package org.dfzt.modules.online.cgform.converter.aa;

import java.util.List;
import java.util.Map;

import org.dfzt.common.system.service.ISysBaseAPI;
import org.dfzt.common.system.vo.DictModel;
import org.dfzt.common.util.SpringContextUtils;
import org.dfzt.common.util.oConvertUtils;
import org.dfzt.modules.online.cgform.converter.FieldCommentConverter;


public class a implements FieldCommentConverter {
    protected ISysBaseAPI iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
    protected String field;
    protected String table;

    public a(String table, String code, String text) {
        this();
        this.table = table;
        this.code = code;
        this.text = text;
    }

    protected String code;
    protected String text;

    public a() {
    }

    public String getField() {
        return this.field;
    }


    public void setField(String field) {
        this.field = field;
    }


    public String getTable() {
        return this.table;
    }


    public void setTable(String table) {
        this.table = table;
    }


    public String getCode() {
        return this.code;
    }


    public void setCode(String code) {
        this.code = code;
    }


    public String getText() {
        return this.text;
    }


    public void setText(String text) {
        this.text = text;
    }


    @Override
    public String converterToVal(String txt) {
        if (oConvertUtils.isNotEmpty(txt)) {
            String str1 = this.text + "= '" + txt + "'";
            String str2 = null;
            int i = this.table.indexOf("where");
            if (i > 0) {
                str2 = this.table.substring(0, i).trim();
                str1 = str1 + " and " + this.table.substring(i + 5);
            } else {
                str2 = this.table;
            }
            List list = this.iSysBaseAPI.queryFilterTableDictInfo(str2, this.text, this.code, str1);
            if (list != null && list.size() > 0) {
                return ((DictModel) list.get(0)).getValue();
            }
        }
        return null;
    }


    @Override
    public String converterToTxt(String val) {
        if (oConvertUtils.isNotEmpty(val)) {
            String str1 = this.code + "= '" + val + "'";
            String str2 = null;
            int i = this.table.indexOf("where");
            if (i > 0) {
                str2 = this.table.substring(0, i).trim();
                str1 = str1 + " and " + this.table.substring(i + 5);
            } else {
                str2 = this.table;
            }
            List list = this.iSysBaseAPI.queryFilterTableDictInfo(str2, this.text, this.code, str1);
            if (list != null && list.size() > 0) {
                return ((DictModel) list.get(0)).getText();
            }
        }
        return null;
    }


    @Override
    public Map<String, String> getConfig() {
        return null;
    }
}
